package com.waitingresult.designpattern.creation.factory.ordinary;

public class OrdinaryFactoryDemo {
    /**
     * 普通静态工厂模式的实例代码
     */
    public static void main(String[] args) {
        Phone redMi = PhoneFactory.getPhone("RedMi");
        redMi.call();
    }
}

class PhoneFactory {
    public static Phone getPhone(String type) {
        if (type.equals("RedMi")) {
            return new RedMiPhone();
        } else if (type.equals("Apple")) {
            return new ApplePhone();
        }
        return null;
    }
}

//定义一个 抽象的手机类.
abstract class Phone {
    public abstract void call();
}

class RedMiPhone extends Phone {
    @Override
    public void call() {
        System.out.println("红米手机打电话");
    }

}

class ApplePhone extends Phone {
    @Override
    public void call() {
        System.out.println("苹果手机打电话");
    }

}
